﻿using System;
using System.Windows.Input;

namespace BingleMaps.Extensions
{
	public static class DelegateExtensions
	{
		public static void ExecuteIfNotNull<T>(this Action<T> action, T obj)
		{
			if (action == null)
			{
				return;
			}
			action(obj);
		}

		public static void ExecuteIfNotNull<T>(this EventHandler<T> handler, object sender, T e) where T : EventArgs
		{
			if (handler == null)
			{
				return;
			}
			handler(sender, e);
		}

		public static void ExecuteIfNotNull(this ICommand command, object parameter = null)
		{
			if (command == null)
			{
				return;
			}
			command.Execute(parameter);
		}
	}
}
